package gt.edu.usac.viewcontroller.backing.app;

import gt.edu.usac.model.am.AppModuleImpl;
import gt.edu.usac.model.vo.TemporadaViewImpl;
import gt.edu.usac.viewcontroller.utils.JSFUtils;

import java.io.IOException;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.faces.component.UISelectItems;
import javax.faces.component.html.HtmlForm;

import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.model.SelectItem;

import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCDataControl;
import oracle.adf.view.faces.component.core.input.CoreSelectOneChoice;
import oracle.adf.view.faces.component.core.layout.CorePanelTip;
import oracle.adf.view.faces.component.core.nav.CoreCommandButton;
import oracle.adf.view.faces.component.core.output.CoreOutputText;

import oracle.jbo.ApplicationModule;

public class InscritosXprofesor {
    private HtmlForm form1;
    private CorePanelTip panelTip1;
    private CoreOutputText outputText1;
    private List<SelectItem> anios;
    private CoreSelectOneChoice selectOneChoice1;
    private UISelectItems selectItems1;
    String anioSelected;
    private CoreCommandButton commandButton1;
    private CoreSelectOneChoice navList1;
    private UISelectItems selectItems2;

    public void setForm1(HtmlForm form1) {
        this.form1 = form1;
    }

    public HtmlForm getForm1() {
        return form1;
    }

    public void setPanelTip1(CorePanelTip panelTip1) {
        this.panelTip1 = panelTip1;
    }

    public CorePanelTip getPanelTip1() {
        return panelTip1;
    }

    public void setOutputText1(CoreOutputText outputText1) {
        this.outputText1 = outputText1;
    }

    public CoreOutputText getOutputText1() {
        return outputText1;
    }

    public void setAnios(List<SelectItem> anios) {
        this.anios = anios;
    }

    public List<SelectItem> getAnios() {
        if(anios==null){
            anios = new ArrayList<SelectItem>();
            int currentAnio = Calendar.getInstance().get(Calendar.YEAR);
            for(int newAnio = 2010; newAnio <= currentAnio+1; newAnio++){
                anios.add(new SelectItem(newAnio));
            }
            
        }
        return anios;
    }

    public void setSelectOneChoice1(CoreSelectOneChoice selectOneChoice1) {
        this.selectOneChoice1 = selectOneChoice1;
    }

    public CoreSelectOneChoice getSelectOneChoice1() {
        return selectOneChoice1;
    }

    public void setSelectItems1(UISelectItems selectItems1) {
        this.selectItems1 = selectItems1;
    }

    public UISelectItems getSelectItems1() {
        return selectItems1;
    }

    public void setAnioSelected(String anioSelected) {
        this.anioSelected = anioSelected;
    }

    public String getAnioSelected() {
        return anioSelected;
    }


    public void setCommandButton1(CoreCommandButton commandButton1) {
        this.commandButton1 = commandButton1;
    }

    public CoreCommandButton getCommandButton1() {
        return commandButton1;
    }

    public String showReport_action() {
        //String anioSelected = JSFUtils.resolveExpression("#{bindings.aniox.inputValue}").toString();
        AppModuleImpl service = getService();
        TemporadaViewImpl temp = service.getTemporadaView1();
        String temporada = temp.getCurrentRow().getAttribute("IdTipoTemporada").toString();
        String anioSelected = temp.getCurrentRow().getAttribute("Anio").toString();
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("/viewcontroller/printprofalumno?reporte=porprofesor&temp="+temporada+"&anio="+anioSelected);
        } catch (IOException e) {
            // TODO
        }
        return null;
    }
    
    private AppModuleImpl getService(){
        FacesContext ctx = FacesContext.getCurrentInstance();
        
        //Creando el binding container 
        ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
        BindingContext bc = (BindingContext)vb.getValue(ctx);
        
        DCDataControl dc  = bc.findDataControl("AppModuleDataControl");
        ApplicationModule am = (ApplicationModule)dc.getDataProvider();
        return (AppModuleImpl)am;
    }


    public void setNavList1(CoreSelectOneChoice navList1) {
        this.navList1 = navList1;
    }

    public CoreSelectOneChoice getNavList1() {
        return navList1;
    }

    public void setSelectItems2(UISelectItems selectItems2) {
        this.selectItems2 = selectItems2;
    }

    public UISelectItems getSelectItems2() {
        return selectItems2;
    }
}
